package com.al.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Update {
	public static void main(String[] args) throws ClassNotFoundException,SQLException {
		//1.加载数据库驱动
		Class.forName("com.mysql.cj.jdbc.Driver");
		//2.建立连接
		String url = "jdbc:mysql://localhost:3306/jdbcdemo?serverTimezone=UTC";
		String user = "root";
		String password = "";
		Connection connection = DriverManager.getConnection(url, user, password);
		//3.获取发送执行对象，定义sql语句
		Statement statement = connection.createStatement();
		String sql = "update users set username='詹姆斯' where id = 23";
		//4.执行sql
		int i = statement.executeUpdate(sql);
		//5.处理返回结果
		System.out.println("有"+i+"条记录被执行");
		//6.关闭资源
		statement.close();
		connection.close();
	}
}
